using System.Linq;
using System;

namespace PersonalAccoutingProgram.Data
{
    partial class ExpensesViewDataClassesDataContext
    {
        public static IQueryable<decimal> GetAllExpensesForDay(
            DateTime date, string username)
        {
            ExpensesViewDataClassesDataContext expensesDC =
            new ExpensesViewDataClassesDataContext();
            var allExpensesForDate =
            from currentExpenses in expensesDC.GetTable<ExpensesView>()
            where currentExpenses.ExpenseDate == date && 
                  currentExpenses.Username == username
            select currentExpenses.ExpenseAmount;
            return allExpensesForDate;
        }

        public static IQueryable<decimal> GetExpensesForDayByCategory(
            DateTime date, string username, string category)
        {
            ExpensesViewDataClassesDataContext expensesDC =
            new ExpensesViewDataClassesDataContext();
            var allExpensesForDate =
            from currentExpenses in expensesDC.GetTable<ExpensesView>()
            where currentExpenses.ExpenseDate == date &&
                  currentExpenses.Username == username &&
                  category == currentExpenses.CategoryName
            select currentExpenses.ExpenseAmount;
            return allExpensesForDate;
        }

        public static IQueryable<decimal> GetExpensesForMonth(
            string username, DateTime dateForCheck)
        {
            ExpensesViewDataClassesDataContext expensesDC =
            new ExpensesViewDataClassesDataContext();
            var allExpensesForUser =
            from currentExpenses in expensesDC.GetTable<ExpensesView>()
            where currentExpenses.Username == username &&
                  currentExpenses.ExpenseDate.Year == dateForCheck.Year &&
                  currentExpenses.ExpenseDate.Month == dateForCheck.Month
            select currentExpenses.ExpenseAmount;
            return allExpensesForUser;
        }

        public static IQueryable<decimal> GetExpensesForMonthByCategory(
            string username, DateTime dateForCheck, string category)
        {
            ExpensesViewDataClassesDataContext expensesDC =
            new ExpensesViewDataClassesDataContext();
            var allExpensesForUser =
            from currentExpenses in expensesDC.GetTable<ExpensesView>()
            where currentExpenses.Username == username && 
                  category == currentExpenses.CategoryName &&
                  currentExpenses.ExpenseDate.Year == dateForCheck.Year &&
                  currentExpenses.ExpenseDate.Month == dateForCheck.Month
            select currentExpenses.ExpenseAmount;
            return allExpensesForUser;
        }

        public static IQueryable<decimal> GetExpensesForYear(
            string username, DateTime dateForCheck)
        {
            ExpensesViewDataClassesDataContext expensesDC =
            new ExpensesViewDataClassesDataContext();
            var allExpensesForUser =
            from currentExpenses in expensesDC.GetTable<ExpensesView>()
            where currentExpenses.Username == username &&
                  currentExpenses.ExpenseDate.Year == dateForCheck.Year
            select currentExpenses.ExpenseAmount;
            return allExpensesForUser;
        }

        public static IQueryable<decimal> GetExpensesForYearByCategory(
            string username, string category, DateTime dateForCheck)
        {
            ExpensesViewDataClassesDataContext expensesDC =
            new ExpensesViewDataClassesDataContext();
            var allExpensesForUser =
            from currentExpenses in expensesDC.GetTable<ExpensesView>()
            where currentExpenses.Username == username &&
                  currentExpenses.CategoryName == category &&
                  currentExpenses.ExpenseDate.Year == dateForCheck.Year
            select currentExpenses.ExpenseAmount;
            return allExpensesForUser;
        }

        public static IQueryable<ExpensesView> GetAllUserExpenses(string username)
        {
            ExpensesViewDataClassesDataContext expensesDC =
            new ExpensesViewDataClassesDataContext();
            var allExpensesForUser =
            from currentExpenses in expensesDC.GetTable<ExpensesView>()
            where currentExpenses.Username == username
            select currentExpenses;
            return allExpensesForUser;
        }

        public static IQueryable<ExpensesView> GetAllUserExpensesByCategory(
            string username, string category)
        {
            ExpensesViewDataClassesDataContext expensesDC =
            new ExpensesViewDataClassesDataContext();
            var allExpensesForUser =
            from currentExpenses in expensesDC.GetTable<ExpensesView>()
            where currentExpenses.Username == username &&
                  currentExpenses.CategoryName == category
            select currentExpenses;
            return allExpensesForUser;
        }
    }
}